package com.jctrip.hotel.source.controller;

import com.jctrip.hotel.common.util.JsonUtil;
import com.jctrip.hotel.source.model.Result;
import com.jctrip.hotel.source.model.hworld.HworldCallBackRequestBody;
import com.jctrip.hotel.source.mq.HotelCallbackDefaultMqProducer;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("test/rocketmq")
@Slf4j
public class TestRocketMqController {

    @Autowired
    private HotelCallbackDefaultMqProducer hotelCallbackDefaultMqProducer;

    @PostMapping("/hworldCallback")
    @ApiOperation("hworldCallback")
    public Result hworldCallback(@RequestBody HworldCallBackRequestBody req) {
        String msg = JsonUtil.toString(req);
        if (StringUtils.isNotBlank(msg)) {
            hotelCallbackDefaultMqProducer.send(msg);
        }
        return Result.ok(msg + " is sent!");
    }
}